package com.itcz.cli.command;

import cn.hutool.core.bean.BeanUtil;
import com.itcz.generator.MainGenerator;
import com.itcz.model.MainTemplateConfig;
import lombok.Data;
import picocli.CommandLine;

import java.util.concurrent.Callable;

/**
 * Generator子命令逻辑
 */
@Data
@CommandLine.Command(name = "generate", description = "生成代码", mixinStandardHelpOptions = true)
public class GeneratorCommand implements Callable<Integer> {

    @CommandLine.Option(names = {"-a", "--author"}, description = "作者信息", arity = "0..1", interactive = true, echo = true)
    private String author = "奥数定理";

    @CommandLine.Option(names = {"-o", "--outputText"}, description = "输出信息", arity = "0..1", interactive = true, echo = true)
    private String outputText = "输出结果：";

    @CommandLine.Option(names = {"-l", "--loop"}, description = "是否循环", arity = "0..1", interactive = true, echo = true)
    private boolean loop = false;


    @Override
    public Integer call() throws Exception {
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        // 使用Hutool工具包提供的方法将该类中的属性复制给mainTemplateConfig对象
        BeanUtil.copyProperties(this, mainTemplateConfig);
        // 执行核心生成器中的doGenerator方法
        MainGenerator.doGenerator(mainTemplateConfig);
        return 0;
    }
}
